home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_023 / ver30 / tty / amigados / ttyio.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  109 lines

  1. /*
  2.  * Name:    MicroEMACS
  3.  *        AmigaDOS terminal I/O
  4.  * Version:    31
  5.  * Compiler:    Manx Aztec C
  6.  * Last edit:    19-Apr-86 ...!ihnp4!seismo!ut-sally!ut-ngp!mic
  7.  * Created:    19-Apr-86 ...!ihnp4!seismo!ut-sally!ut-ngp!mic
  8.  */
  9. #include    <libraries/dos.h>
  10. #include    <libraries/dosextens.h>
  11. #undef TRUE
  12. #undef FALSE
  13. #include    "def.h"
  14. #include    "sysdef.h"
  15.  
  16. #define    NIBUF    128            /* Probably excessive.        */
  17. #define    NOBUF    512            /* Not too big for 750/730.    */
  18.  
  19. struct    FileHandle    *tty;
  20. struct    FileHandle    *Open();
  21. char    obuf[NOBUF];            /* Output buffer        */
  22. int    nobuf;                /* # of bytes in above        */
  23. char    ibuf[NIBUF];            /* Input buffer            */
  24. int    nibuf;                /* # of bytes in above        */
  25. int    nrow;                /* Terminal size, rows.        */
  26. int    ncol;                /* Terminal size, columns.    */
  27. #if    MANX
  28. extern    int    Enable_Abort;
  29. #endif
  30.  
  31. extern    char    *version[];    /* Defined in "version.c"    */
  32. /*
  33.  * This routine gets called once, to set up the
  34.  * terminal channel.
  35.  */
  36. ttopen()
  37. {
  38.     char WindowName[80];
  39.     
  40.     nrow = 23;
  41.     ncol = 77;
  42.     nobuf = nibuf = 0;
  43. #if    MANX
  44.     Enable_Abort = 0;    /* Disable ^C during file I/O */
  45. #endif
  46.     strcpy(WindowName,"RAW:1/1/639/199/");
  47.     strcat(WindowName,version[0]);
  48.     tty = Open(WindowName,MODE_NEWFILE);
  49.     if (tty == (struct FileHandle *) 0) {
  50.         printf("Can't open Emacs window!\n");
  51.         exit(200);
  52.     }
  53. }
  54.  
  55. /*
  56.  * This function gets called just
  57.  * before we go back home to the command interpreter.
  58.  * On the Amiga it closes up the virtual terminal window.
  59.  */
  60. ttclose()
  61. {
  62.     if (tty != (struct FileHandle *) 0L) {
  63.         ttflush();
  64.         Close(tty);
  65.     }
  66.     tty = (struct FileHandle *) 0L;
  67. #if    MANX
  68.     Enable_Abort = 1;
  69. #endif
  70. }
  71.  
  72. /*
  73.  * Write a character to the display.
  74.  * On the Amiga, terminal output is buffered, and
  75.  * we just put the characters in the big array,
  76.  * after cheching for overflow.
  77.  */
  78. ttputc(c)
  79. {
  80.     if (nobuf >= NOBUF)
  81.         ttflush();
  82.     obuf[nobuf++] = c;
  83. }
  84.  
  85. /*
  86.  * This function does the real work of
  87.  * flushing out buffered I/O on the Amiga. All
  88.  * we do is blast out the block with a write call.
  89.  */
  90. ttflush()
  91. {
  92.     if (nobuf > 0) {
  93.         Write(tty,obuf,(long) nobuf);
  94.         nobuf = 0;
  95.     }
  96. }
  97.  
  98. /*
  99.  * Read a character from the terminal,
  100.  * performing no editing and doing no echo at all.
  101.  */
  102. ttgetc()
  103. {
  104.     unsigned char c;    /* must be unsigned! */
  105.  
  106.     Read(tty,&c,1L);
  107.     return ((int) c);
  108. }
  109.